suppressPackageStartupMessages({
  library(ggplot2)
  library(dplyr)
  
  requireNamespace("plotly")
})

Preliminaries

Introduction

plotter <- function(df) {
  df %>%
    with({
      plotly::plot_ly() %>%
      plotly::add_markers(
        x = x, y = y, z = z,
        color = group
      )
    })
}

Pre-Test

randu %>%
  ggplot(aes(x = x, y = y)) + geom_point()

Test 2

randu %>%
  mutate(group = (1:nrow(.)) %% 3) %>%
  plotter()

Test 3

randu %>%
  mutate(group = (1:nrow(.)) %% 3) %>%
  plotter()